<template>
  <div class="upload-work-page">
    <el-card class="upload-card">
      <div class="title">上传作品</div>
      <el-form label-width="100px">
        <el-form-item label="竞赛ID">
          <ContestSelector v-model="contestId" />
        </el-form-item>
        <el-form-item label="题目选择" v-if="contestId">
          <TopicSelector :contestId="contestId" @change="onTopicChange" />
        </el-form-item>
        <el-form-item label="上传作品" v-if="contestId && topicId">
          <FileUpload :contestId="contestId" :topicId="topicId" @success="onUploadSuccess" />
        </el-form-item>
      </el-form>
      <el-dialog v-model="dialogVisible" title="上传结果" width="400px" :close-on-click-modal="false">
        <div v-if="uploadResult">
          <p>上传成功，作品ID：<b>{{ uploadResult.workId }}</b></p>
          <p>论文文件名：<b>{{ uploadResult.thesisName }}</b></p>
        </div>
        <template #footer>
          <el-button type="primary" @click="dialogVisible = false">确定</el-button>
        </template>
      </el-dialog>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import ContestSelector from '@/components/ContestSelector.vue'
import TopicSelector from '@/components/TopicSelector.vue'
import FileUpload from '@/components/FileUpload.vue'

const contestId = ref('')
const topicId = ref('')
const dialogVisible = ref(false)
const uploadResult = ref(null)

const onTopicChange = (topic) => {
  topicId.value = topic?.id || ''
}

const onUploadSuccess = (data) => {
  uploadResult.value = data
  dialogVisible.value = true
}
</script>

<style scoped>
.upload-work-page {
  max-width: 600px;
  margin: 40px auto;
}
.upload-card {
  padding: 32px 32px 24px 32px;
  border-radius: 10px;
  box-shadow: 0 2px 16px 0 rgba(60,90,150,0.08);
}
.title {
  font-size: 22px;
  font-weight: bold;
  margin-bottom: 24px;
  letter-spacing: 2px;
  color: #2d3a4b;
}
</style>
